gtkpasswordentry: Add a "catchall" click gesture handler
authorCarlos Garnacho <carlosg@gnome.org>
Mon, 23 Aug 2021 23:13:29 +0000 (01:13 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Mon, 23 Aug 2021 23:13:29 +0000 (01:13 +0200)
This gesture is set on the whole widget surface, since there's
multiple input targets inside an entry (icons, the GtkText itself)
it makes sense to consider the full entry an area handling clicks.
Ensure these events don't propagate further up, and result in other
actions.

gtk/gtkpasswordentry.c

index ba91de58f4065ffa823b3e1be337692358bd66f3..7e375a05bcf7c814ec69bec8719d131cd475fafe 100644 (file)
@@ -188,9 +188,20 @@ activate_cb (GtkPasswordEntry *entry)
   g_signal_emit (entry, signals[ACTIVATE], 0);
 }
 
+static void
+catchall_click_press (GtkGestureClick *gesture,
+                      int              n_press,
+                      double           x,
+                      double           y,
+                      gpointer         user_data)
+{
+  gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+}
+
 static void
 gtk_password_entry_init (GtkPasswordEntry *entry)
 {
+  GtkGesture *catchall;
   GtkEntryBuffer *buffer = gtk_password_entry_buffer_new ();
 
   entry->entry = gtk_text_new ();
@@ -207,6 +218,12 @@ gtk_password_entry_init (GtkPasswordEntry *entry)
   gtk_widget_set_cursor (entry->icon, gtk_widget_get_cursor (entry->entry));
   gtk_widget_set_parent (entry->icon, GTK_WIDGET (entry));
 
+  catchall = gtk_gesture_click_new ();
+  g_signal_connect (catchall, "pressed",
+                    G_CALLBACK (catchall_click_press), entry);
+  gtk_widget_add_controller (GTK_WIDGET (entry),
+                             GTK_EVENT_CONTROLLER (catchall));
+
   gtk_widget_add_css_class (GTK_WIDGET (entry), I_("password"));
 
   gtk_password_entry_set_extra_menu (entry, NULL);